package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.baseComponentPojo;
import com.example.pojo.componentBookPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * ClassName:componentBookMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/12 17:09
 * @Version 1.0
 */
@Mapper
public interface componentBookMapp {
    @DS("baodingRussia")
    //插入一行新的数据
    @Insert("insert into component_book " +
            "(partName, partNumber, supplier, " +
            "threeNoBook, threeNoBookAnnex,baseId," +
            "establishTime, UpdateTime) " +
            "VALUES " +
            "(#{partName},#{partNumber},#{supplier}," +
            "#{threeNoBook},#{threeNoBookAnnex},#{baseId}," +
            "#{establishTime},#{UpdateTime})")
    void insertOne(componentBookPojo componentBookPojo);
    //对零部件作业指导书管理中的数据进行修订,依据是baseId
    @DS("baodingRussia")
    @Update("update component_book set " +
            "partNumber=#{partNumber}," +
            "partName=#{partName}," +
            "supplier=#{supplier}" +
            " where baseId=#{id}")
    void editByBaseId(baseComponentPojo baseComponent);
    //根据baseId，查询某一个字段的内容
    @DS("baodingRussia")
    @Select("select * from component_book where baseId=#{baseId}")
    componentBookPojo inquiryByFieldAndBaseId(Integer baseId);

    //修改数据，发id，修改的字段名，修改的字段值,根据ID，修改某一个字段的值,修改的是文本。
    @DS("baodingRussia")
    @Update("update component_book set threeNoBook=#{fieldVal} where id=#{id}")
    void editComponentBookByIDByField(Integer id, String fieldName, String fieldVal);
    //根据传来的字段名，修改字段
    @DS("baodingRussia")
    @Update("update component_book set ${fieldName}=#{fileNameAll},UpdateTime=#{dateTime} where id=#{id}")
    void editFieldOneById(Integer id, String fieldName, String fileNameAll, LocalDateTime dateTime);
}
